package com.probox.modules.controller.customer;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.entity.domain.customer.RechargeInfo;
import com.probox.common.entity.service.customer.IRechargeInfoService;
import com.probox.common.entity.service.recharge.IRechargeRecordService;
import com.probox.common.entity.vo.recharge.RechargeRecordVo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 储值信息Controller
 *
 * @author usoft
 * @date 2022-09-14
 */
@RestController
@RequestMapping("/system/info")
public class RechargeInfoController extends BaseController {
    @Autowired
    private IRechargeInfoService rechargeInfoService;

    @Autowired
    private IRechargeRecordService rechargeRecordService;

    /**
     * 储值明细列表
     *
     * @param vo
     * @return
     */
    @GetMapping("/record/list")
    public TableDataInfo getList(RechargeRecordVo vo) {
        startPage();
        List<RechargeRecordVo> list = rechargeRecordService.getList(vo);
        return getDataTable(list);
    }

    /**
     * 查询储值信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RechargeInfo rechargeInfo) {
        startPage();
        List<RechargeInfo> list = rechargeInfoService.getList(rechargeInfo);
        return getDataTable(list, rechargeInfoService.queryCount(rechargeInfo));
    }

    /**
     * 导出储值信息列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, RechargeInfo rechargeInfo) throws IOException {
        List<RechargeInfo> list = rechargeInfoService.queryList(rechargeInfo);
        ExcelUtil<RechargeInfo> util = new ExcelUtil<RechargeInfo>(RechargeInfo.class);
        util.exportExcel(response, list, "储值信息数据");
    }

    /**
     * 获取储值信息详细信息
     */
    @GetMapping(value = "/{rechargeId}")
    public AjaxResult getInfo(@PathVariable("rechargeId") Long rechargeId) {
        return AjaxResult.success(rechargeInfoService.getRecharge(rechargeId));
    }

    /**
     * 新增储值信息
     */
    // @PreAuthorize(hasPermi = "system:info:add")
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody RechargeInfo rechargeInfo) {
        return toAjax(rechargeInfoService.addOrEditRecharge(rechargeInfo));
    }

    /**
     * 修改储值信息
     */
    // @PreAuthorize(hasPermi = "system:info:edit")
    @PutMapping(value = "/edit")
    public AjaxResult edit(@RequestBody RechargeInfo rechargeInfo) {
        return toAjax(rechargeInfoService.addOrEditRecharge(rechargeInfo));
    }

    /**
     * 修改商品设备状态
     */
    // @PreAuthorize(hasPermi = "system:brand:edit")
    @Log(title = "商品设备", businessType = BusinessType.UPDATE)
    @PutMapping("/updateBrandStatus")
    public AjaxResult update(@RequestBody RechargeInfo rechargeInfo) {
        return toAjax(rechargeInfoService.updateRechargeInfo(rechargeInfo));
    }

    /**
     * 删除储值信息
     */
    //  @PreAuthorize(hasPermi = "system:info:remove")
    @DeleteMapping("/{rechargeIds}")
    public AjaxResult remove(@PathVariable Long[] rechargeIds) {
        return toAjax(rechargeInfoService.deleteRechargeInfoByIds(rechargeIds));
    }
}
